package org.example.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class DiyAnnotation {
    @Pointcut("execution(* org.example.aop.service.Userserviceimpl.*(..))")
    public void pt(){}

//    @Before("pt()")
//    public void before(){
//        System.out.println("前置方法执行前");
//    }
//
//    @AfterReturning("pt()")
//    public void after(){
//        System.out.println("后置方法执行后");
//    }

    // 环绕
    @Around("pt()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕方法执行前");
        //获取方法签名
        Signature signature = joinPoint.getSignature();
        System.out.println("方法签名:"+signature);
        Object[] args = joinPoint.getArgs();
        System.out.println("参数列表"+ Arrays.toString(args));
        String proceed = (String) joinPoint.proceed(); //执行了del()方法
        System.out.println("环绕方法的返回结果是:"+proceed);

        System.out.println("环绕方法执行后");
        return proceed.toUpperCase();
    }
}
